﻿/*
 * 版 本 v1.0
 * Copyright (c) 2013-2018 广州市同慧信息科技有限公司
 * 创建人：ftquan
 * 日 期：2017.04.18
 * 描 述：成员查看
 */
var companyId = request('companyId');
var ztId = request('ztId');

var bootstrap = function ($, learun) {
    "use strict";

    var page = {
        init: function () {
            page.bind();
            page.initData();
        },
        bind: function () {
            // 滚动条
            $('#user_list_warp').lrscroll();
            // 搜索
            $("#txt_keyword").keydown(function (event) {
                if (event.keyCode == 13) {
                    var keyword = $(this).val();
                    learun.httpAsync('GET', config.base_server() + 'gzztusers/list?companyId=' + companyId + '&ztId=' + ztId + '&keyword=' + keyword + '&access_token=' + config.getToken().access_token, {}, function (data) {
                        if (data.userIds == "") {
                            return false;
                        }
                        var $warp = $('#user_list');
                        $warp.empty();
                        var userlistselectedobj = {};
                        $.each(data.userInfoList, function (id, item) {
                            if (item) {
                                userlistselectedobj[item.id] = item;
                            }
                        });
                        var userList = data.userIds.split(',');
                        for (var i = 0, l = userList.length; i < l; i++) {
                            var userId = userList[i];
                            var item = userlistselectedobj[userId];
                            if (!!item) {
                                var _cardbox = "";
                                _cardbox += '<div class="card-box active " data-value="' + item.id + '" >';
                                _cardbox += '    <div class="card-box-content">';
                                _cardbox += '        <p>编号：' + item.userCode + '</p>';
                                _cardbox += '        <p>姓名：' + item.realName + '</p>';
                                _cardbox += '        <p>部门：<span data-id="' + item.departmentId + '"></span></p>';
                                _cardbox += '    </div>';
                                _cardbox += '</div>';
                                $warp.append(_cardbox);
                                learun.clientdata.getAsync('department', {
                                    key: item.departmentId,
                                    callback: function (_data, op) {
                                        $warp.find('[data-id="' + op.key + '"]').text(_data.name);
                                    }
                                });
                            }
                        }
                        $("#total_count").html(userList.length +"人");
                    });

                }
            });
        },
        initData: function () {
            $.lrSetForm(config.base_server() + 'gzztusers/list?companyId=' + companyId + '&ztId=' + ztId, function (data) {
                if (data.userIds == "") {
                    return false;
                }
                var $warp = $('#user_list');
                var userlistselectedobj = {};
                $.each(data.userInfoList, function (id, item) {
                    if (item) {
                        userlistselectedobj[item.id] = item;
                    }
                });
                var userList = data.userIds.split(',');
                for (var i = 0, l = userList.length; i < l; i++) {
                    var userId = userList[i];
                    var item = userlistselectedobj[userId];
                    if (!!item) {
                        var _cardbox = "";
                        _cardbox += '<div class="card-box active " data-value="' + item.id + '" >';
                        _cardbox += '    <div class="card-box-content">';
                        _cardbox += '        <p>编号：' + item.userCode + '</p>';
                        _cardbox += '        <p>姓名：' + item.realName + '</p>';
                        _cardbox += '        <p>部门：<span data-id="' + item.departmentId + '"></span></p>';
                        _cardbox += '    </div>';
                        _cardbox += '</div>';
                        $warp.append(_cardbox);
                        learun.clientdata.getAsync('department', {
                            key: item.departmentId,
                            callback: function (_data, op) {
                                $warp.find('[data-id="' + op.key + '"]').text(_data.name);
                            }
                        });
                    }
                }
                $("#total_count").html(userList.length +"人");
            });
        }
    };
    page.init();
}